%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%             HW 1 (#4): Signal Representation in Matlab                  %
%                       EE556: Dr. fred harris                            %
%                     Author: Michael Spinali                             %
%                             813488956                                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Create Fresh Environment
close all
clear all
clc

%Define Functions
s1a=10*cos(2*pi*(0:199)*(5/100)-2*pi*0);
s1b=10*cos(2*pi*(0:199)*(5/200)-2*pi*0);

s2a=10*cos(2*pi*(0:199)*(5/100)-pi/2);
s2b=10*cos(2*pi*(0:199)*(5/200)-pi/2);

s3a=10*exp(1i*2*pi*(0:199)*(10/100)+1i*2*pi*0);
s3b=10*exp(1i*2*pi*(0:199)*(10/200)+1i*2*pi*0);

s4a=10*exp(1i*2*pi*(0:199)*(-10/100)+1i*pi/2);
s4b=10*exp(1i*2*pi*(0:199)*(-10/200)+1i*pi/2);

%%%%S1%%%%
figure('name','Signal 1 (S1)');
subplot(2,2,1)
plot(0:199,real(s1a),'linewidth',2)
hold on
plot(0:199,imag(s1a),'r','linewidth',2)
hold off
axis([0 100 -12 12])
grid on
title('Time series, s1a = 10*cos(2*\pi*(0:99)*5/100)','fontsize',14)
xlabel('Time Index','fontsize',14)
ylabel('Amplitude','fontsize',14)
 
subplot(4,2,2)
fs1a=fftshift(fft(s1a));
stem((-0.5:1/200:0.5-1/200)*100,real(fs1a),'linewidth',2)
hold off
grid on
title('Real Part 200 Point FFT(s1a)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(4,2,4)
stem((-0.5:1/200:0.5-1/200)*100,imag(fs1a),'r','linewidth',2)
grid on
title('Imaginary Part 200 Point FFT(s1a)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(2,2,3)
plot(0:199,real(s1b),'linewidth',2)
hold on
plot(0:199,imag(s1b),'r','linewidth',2)
hold off
axis([0 100 -12 12])
grid on
title('Time series, s1b = 10*cos(2*\pi*(0:99)*5/200 + 2*pi*0)','fontsize',14)
xlabel('Time Index','fontsize',14)
ylabel('Amplitude','fontsize',14)
 
subplot(4,2,6)
fs1b=fftshift(fft(s1b));
stem((-0.5:1/200:0.5-1/200)*200,real(fs1b))
hold off
grid on
title('Real Part 200 Point FFT(s1b)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(4,2,8)
stem((-0.5:1/200:0.5-1/200)*200,imag(fs1b),'r')
grid on
title('Imaginary Part 200 Point FFT(s1b)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')

%%%%S2%%%%
figure('name','Signal 2 (S2)');
subplot(2,2,1)
plot(0:199,real(s2a),'linewidth',2)
hold on
plot(0:199,imag(s2a),'r','linewidth',2)
hold off
axis([0 100 -12 12])
grid on
title('Time series, s2a = 10*cos(2*\pi*(0:99)*5/100 - pi/2)','fontsize',14)
xlabel('Time Index','fontsize',14)
ylabel('Amplitude','fontsize',14)
 
subplot(4,2,2)
fs2a=fftshift(fft(s2a));
stem((-0.5:1/200:0.5-1/200)*100,real(fs2a),'linewidth',2)
hold off
grid on
title('Real Part 200 Point FFT(s2a)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(4,2,4)
stem((-0.5:1/200:0.5-1/200)*100,imag(fs2a),'r','linewidth',2)
grid on
title('Imaginary Part 200 Point FFT(s2a)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(2,2,3)
plot(0:199,real(s2b),'linewidth',2)
hold on
plot(0:199,imag(s2b),'r','linewidth',2)
hold off
axis([0 100 -12 12])
grid on
title('Time series, s2b = 10*cos(2*\pi*(0:99)*5/200 - pi/2)','fontsize',14)
xlabel('Time Index','fontsize',14)
ylabel('Amplitude','fontsize',14)
 
subplot(4,2,6)
fs2b=fftshift(fft(s2b));
stem((-0.5:1/200:0.5-1/200)*200,real(fs2b))
hold off
grid on
title('Real Part 200 Point FFT(s2b)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(4,2,8)
stem((-0.5:1/200:0.5-1/200)*200,imag(fs2b),'r')
grid on
title('Imaginary Part 200 Point FFT(s2b)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')

%%%%s3%%%%
figure('name','Signal 3 (s3)');
subplot(2,2,1)
plot(0:199,real(s3a),'linewidth',2)
hold on
plot(0:199,imag(s3a),'r','linewidth',2)
hold off
axis([0 100 -12 12])
grid on
title('Time series, s3a = 10*exp(j*2*\pi*(0:99)*10/100)','fontsize',14)
xlabel('Time Index','fontsize',14)
ylabel('Amplitude','fontsize',14)
 
subplot(4,2,2)
fs3a=fftshift(fft(s3a));
stem((-0.5:1/200:0.5-1/200)*100,real(fs3a),'linewidth',2)
hold off
grid on
title('Real Part 200 Point FFT(s3a)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(4,2,4)
stem((-0.5:1/200:0.5-1/200)*100,imag(fs3a),'r','linewidth',2)
grid on
title('Imaginary Part 200 Point FFT(s3a)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(2,2,3)
plot(0:199,real(s3b),'linewidth',2)
hold on
plot(0:199,imag(s3b),'r','linewidth',2)
hold off
axis([0 100 -12 12])
grid on
title('Time series, s3b = 10*exp(j*2*\pi*(0:99)*10/200)','fontsize',14)
xlabel('Time Index','fontsize',14)
ylabel('Amplitude','fontsize',14)
 
subplot(4,2,6)
fs3b=fftshift(fft(s3b));
stem((-0.5:1/200:0.5-1/200)*200,real(fs3b))
hold off
grid on
title('Real Part 200 Point FFT(s3b)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(4,2,8)
stem((-0.5:1/200:0.5-1/200)*200,imag(fs3b),'r')
grid on
title('Imaginary Part 200 Point FFT(s3b)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')

%%%%s4%%%%
figure('name','Signal 4 (s4)');
subplot(2,2,1)
plot(0:199,real(s4a),'linewidth',2)
hold on
plot(0:199,imag(s4a),'r','linewidth',2)
hold off
axis([0 100 -12 12])
grid on
title('Time series, s4a = 10*exp(j*2*\pi*(0:99)*(-10/100)+j*pi/2)','fontsize',14)
xlabel('Time Index','fontsize',14)
ylabel('Amplitude','fontsize',14)
 
subplot(4,2,2)
fs4a=fftshift(fft(s4a));
stem((-0.5:1/200:0.5-1/200)*100,real(fs4a),'linewidth',2)
hold off
grid on
title('Real Part 200 Point FFT(s4a)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(4,2,4)
stem((-0.5:1/200:0.5-1/200)*100,imag(fs4a),'r','linewidth',2)
grid on
title('Imaginary Part 200 Point FFT(s4a)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(2,2,3)
plot(0:199,real(s4b),'linewidth',2)
hold on
plot(0:199,imag(s4b),'r','linewidth',2)
hold off
axis([0 100 -12 12])
grid on
title('Time series, s4b = 10*exp(j*2*\pi*(0:99)*(-10/200)+j*pi/2)','fontsize',14)
xlabel('Time Index','fontsize',14)
ylabel('Amplitude','fontsize',14)
 
subplot(4,2,6)
fs4b=fftshift(fft(s4b));
stem((-0.5:1/200:0.5-1/200)*200,real(fs4b))
hold off
grid on
title('Real Part 200 Point FFT(s4b)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
 
subplot(4,2,8)
stem((-0.5:1/200:0.5-1/200)*200,imag(fs4b),'r')
grid on
title('Imaginary Part 200 Point FFT(s4b)')
ylabel('Amplitude')
xlabel('Frequency (kHz)')
